/**
 * 
 */
package com.ai.controller.system;

import java.util.Date;

import javax.annotation.Resource;

import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ai.common.controller.BaseController;
import com.ai.common.exception.AlikAssert;
import com.ai.common.model.Pagination;
import com.ai.common.model.Result;
import com.ai.mmd.system.dto.BtbzinfoDTO;
import com.ai.service.system.model.BtbzinfoModel;
import com.ai.service.system.service.IBtbzinfoService;

/**
 * 港口
 * 
 * @author Administrator
 *
 */
@RequestMapping("btbz")
@Controller("com.ai.controller.system.BzController")
public class BzController extends BaseController {

	/**
	 * 列表
	 * @param gkinfoDTO
	 * @return
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping("list")
	public Pagination<BtbzinfoModel> list(@ModelAttribute BtbzinfoDTO btbzinfoDTO)
			throws Exception {
		if (btbzinfoDTO.getSort()!=null) {
			btbzinfoDTO.setSort(btbzinfoDTO.getSort().concat(" " + btbzinfoDTO.getOrder()));
		}else {
			btbzinfoDTO.setSort("id desc");
		}
		return ibtbzinfoService.getPagination(btbzinfoDTO);
	}
	
	/**
	 * 编辑
	* @date 2016年6月27日 下午9:31:40
	* @param CclxInfoDTO
	* @return
	* @throws Exception
	* List<gkinfoModel>
	 */
	@ResponseBody
	@RequestMapping("neworedit")
	public Result neworedit(@ModelAttribute BtbzinfoDTO btbzinfoDTO,
			@RequestParam(required = true) Integer isflag)
			throws Exception {
		Result rs = new Result(true);
		BtbzinfoModel btbzinfoModel = new BtbzinfoModel();
		switch (isflag) {
		case 0:
			//新增
			AlikAssert.isNotNull(btbzinfoDTO.getCash(), "参数异常.");
			btbzinfoDTO.setCjsj(new Date());
			btbzinfoDTO.setGxsj(new Date());
			BeanUtils.copyProperties(btbzinfoDTO, btbzinfoModel);
			ibtbzinfoService.insert(btbzinfoModel);
			break;
		case 1:
			//编辑
			AlikAssert.isNotNull(btbzinfoDTO.getId(), "参数异常.");
			btbzinfoDTO.setGxsj(new Date());
			BeanUtils.copyProperties(btbzinfoDTO, btbzinfoModel);
			ibtbzinfoService.updateByPrimaryKey(btbzinfoModel);
			break;
		case 2:
			//删除
			AlikAssert.isNotNull(btbzinfoDTO.getId(), "参数异常.");
			btbzinfoDTO.setSfsc(1);
			btbzinfoDTO.setGxsj(new Date());
			BeanUtils.copyProperties(btbzinfoDTO, btbzinfoModel);
			ibtbzinfoService.updateByPrimaryKey(btbzinfoModel);
			break;
		default:
			break;
		}
				
		return rs;
	}
	
	/**
     * 跳转
     * @return
     * @throws Exception
     */
    @RequestMapping("forward")
    public String forward() throws Exception{
        return "system/btbz/list";
    }

	@Resource(name = "ibtbzinfoService")
	private IBtbzinfoService ibtbzinfoService;

}
